/* eslint-disable no-path-concat */
const fs = require('fs');
const path = require('path');
const md = require('markdown-it')('commonmark');
const pretty = require('pretty');

const mdFilePath = path.resolve(__dirname + '/doc/changelog.md');
const targetFilePath = path.resolve(__dirname + '/src/popup/popup.html');

const mdContent = fs.readFileSync(mdFilePath, 'utf-8');
const targetContent = fs.readFileSync(targetFilePath, 'utf-8');

const result = targetContent.replace(
  /(?<=<!-- start -->)([\s\S]*?)(?=<!-- end -->)/,
  md.render(mdContent)
);

fs.writeFileSync(targetFilePath, pretty(result), 'utf-8');
